import axios from "axios";
import { api } from '../config/config'

import store from '@/store/index'

const $http = axios.create({
    baseURL: api,
    timeout: 600000,
});

$http.interceptors.request.use(
    function (config) {
        // config.headers = { 'Content-Type': 'text/plain; charset=UTF-8' }
        store.commit('setLoading', true)
        return config;
    },
    function (error) {
        return Promise.reject(error);
    }
);

$http.interceptors.response.use(
    function (response) {
        store.commit('setLoading', false)
        if (response.status === 200) return response.data
        return response;
    },
    function (error) {
        return Promise.reject(error);
    }
);

export default $http;